#include "stdafx.h"
#include "log4cplus_export.h"
#include <Windows.h>

LOG_FUNCS g_log_funcs;
HMODULE g_log4cplus_mod = 0;

void init_log4cplus (const char* mod_name)
{
	if (g_log4cplus_mod)
		return;

	g_log4cplus_mod = LoadLibrary (mod_name);
	if (!g_log4cplus_mod)
		return;

	g_log_funcs.log_trace = (LOG_FUNC)GetProcAddress (g_log4cplus_mod, "log_trace");
	g_log_funcs.log_info  = (LOG_FUNC)GetProcAddress (g_log4cplus_mod, "log_info");
	g_log_funcs.log_debug = (LOG_FUNC)GetProcAddress (g_log4cplus_mod, "log_debug");
	g_log_funcs.log_warn  = (LOG_FUNC)GetProcAddress (g_log4cplus_mod, "log_warn");
	g_log_funcs.log_error = (LOG_FUNC)GetProcAddress (g_log4cplus_mod, "log_error");
	g_log_funcs.log_fatal = (LOG_FUNC)GetProcAddress (g_log4cplus_mod, "log_fatal");
}

void config_log4cplus (const char* file)
{
	if (!g_log4cplus_mod)
		return;

	typedef void (*CONFIG_FUNC) (const char* file);
	CONFIG_FUNC config_func = (CONFIG_FUNC)GetProcAddress (g_log4cplus_mod, "config_log4cplus");
	if (config_func)
		config_func (file);
}

void fini_log4cplus ()
{
	memset (&g_log_funcs, 0, sizeof (LOG_FUNC));
	FreeLibrary (g_log4cplus_mod);
	g_log4cplus_mod = 0;
}
